package com.android.signhelper.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by ikata on 2018/11/14.
 */

public abstract class BaseActivity<V extends BaseView,P extends BasePresenter<V>> extends AppCompatActivity {

    private V view;
    private P presenter;

    public P getPresenter() {
        return presenter;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (presenter==null)
        {
            presenter=createPresenter();
        }
        if (view==null)
        {
            view=createView();
        }
        presenter.binderView(view);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter!=null){
            presenter.unBinderView();
        }
        if (view!=null){
            view = null;
        }
    }

    protected abstract V createView();
    protected abstract P createPresenter();
}
